package com.yanqu.road.server.manger;

import com.yanqu.road.entity.enums.eChannelType;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.entity.servercenter.whitelist.WhiteAccount;
import com.yanqu.road.logic.bussiness.servercenter.PlatformUserIdInfoBussiness;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class PlatformUserIdMgr extends TempMgr {

	private static List<String> platformUserIdList = new ArrayList<>();

	private static List<WhiteAccount> whiteAccounts = new ArrayList<>(); // 账号白名单列表

	@Override
	public boolean init() throws Exception {
		return reload();
	}

	@Override
	public boolean stop() {
		return false;
	}

	@Override
	public boolean save() {
		return false;
	}

	@Override
	public boolean reloadData() {
		List<String> tempPlatformUserIdList = new ArrayList<>();
		PlatformUserIdInfoBussiness.getPlatformUserIdList(tempPlatformUserIdList);

		platformUserIdList = tempPlatformUserIdList;
		whiteAccounts = PlatformUserIdInfoBussiness.getWhiteAccounts();
		return true;
	}

	@Override
	public boolean reloadConfig() throws Exception {
		return true;
	}

	public static boolean isPlatformUserIdPass(String platformUserId) {
		if(StringUtils.isNullOrEmpty(platformUserId)){
			return false;
		}
		return platformUserIdList.contains(platformUserId);
	}

	public static boolean openBehavior(int type, ServerInfo serverInfo){
		if(type == 1 && ((serverInfo.getChannelId() >= eChannelType.MainLand.getValue() && serverInfo.getChannelId() <= eChannelType.Mobile_QQ.getValue())
				|| serverInfo.getChannelId() == eChannelType.InnerChannel.getValue() || serverInfo.getChannelId() == eChannelType.MainLandBusiness.getValue())){
			return true;
		}
		if(type == 3 && (serverInfo.getChannelId() == 331 || serverInfo.getChannelId() == 303 || serverInfo.getChannelId() == 666)){
			return true;
		}
		return false;
	}

	public static List<WhiteAccount> getWhiteAccounts() {
		return whiteAccounts;
	}
}